class MessageClass {
  constructor(config) {
    if (!MessageClass.instance) {
      const baseConfig = {
        color: "red",
        timeOut: 3000,
      };

      this.config = Object.assign(baseConfig, config);
      MessageClass.instance = this;
    }
    return MessageClass.instance;
  }

  success(msg) {
    this.config.color = "green";
    this.msg = msg;
    this.print("success", msg);
  }

  error(msg) {
    this.config.color = "red";
    this.msg = msg;
    this.print("error", msg);
  }

  print(type) {
    console.log(
      type,
      "::",
      "color=",
      this.config.color,
      "msg=",
      this.msg,
      "timeOut=",
      this.config.timeOut
    );
  }

  setConfig(config) {
    if (MessageClass.instance) {
      MessageClass.instance.config = Object.assign(
        MessageClass.instance.config,
        config
      );
    }
  }
}

const useMessage = (config) => {
  const msg = new MessageClass(config);

  return {
    _setTimeOut: (num) => msg.setConfig({ timeOut: num }),
  };
};

const $message = new MessageClass({ timeOut: 1111 });
console.log($message);
useMessage()._setTimeOut(9999);
console.log($message);
